clear
clear mata
clear matrix

cd ..                                                                            /* Goes back to parent folder */

capture log close

log using "log/10_FDR.log", replace

mkdir "tmp"                                                                      /* creates a temporary folder to store temp files */

*       Patriotism!

*       FIRST VERSION  June       8, 2022
*       THIS VERSION   June       8, 2022
*       LAST RUN       June       8, 2022

*       AUTHORS             BC

*       Log of revisions: 

*       This prepares data on share of votes for FDR in 1940

********************************************************************************
****                        PLAN OF PROCEDURE                               ****
****        1. Merge voting data to ICPSR bridge (1930-ND)                  ****
****        2. Prepare variable of interest                                 ****
****        3. Collapse at the level of ND counties                         ****
********************************************************************************

********************************************************************************
****        1. Merge voting data to ICPSR bridge (1930-ND)                  ****
********************************************************************************
do "code-build/01_Shopping_List.do"

use "rawdata/ICPSR/08611-0001-Data", replace

ren V1 stateicpsr 
ren V3 countyicpsr

merge 1:1 stateicpsr countyicpsr using "rawdata/maps/Bridge.dta", keep(mas mat) /* Not matched 1 from using (DC), 293 from master */

tab V546 if _merge == 1
drop if     _merge == 1 
drop        _merge

********************************************************************************
****        2. Prepare variable of interest                                 ****
********************************************************************************
replace V546 = . if V546 >  100
replace V550 = . if V550 == 9999999

ren V546 FDR40
ren V550 VOTES40

********************************************************************************
****        3. Collapse at the level of ND counties                         ****
********************************************************************************
replace FDR40 = FDR40 * VOTES40
collapse (sum) FDR40 VOTES40 (count) n_FDR40 = FDR40 n_VOTES40 = VOTES40, by(stateicpsr countynd)
replace FDR40 = FDR40 / VOTES40
for VAR in var FDR40 VOTES40 : replace VAR = . if n_VAR == 0
drop n_* VOTES40 

lab var FDR40   "Percent vote for FDR 1940 (ICPSR)"

save "data/FDR40", replace

log close
exit